<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/resource/treeAdd">
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-3 control-label">父菜单ID：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="parentId" name="parentId" value="${parentId}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单名称：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="resourceName" name="resourceName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单类型：</label>
            <div class="col-sm-9">
                <select class="col-sm-5" id="resourceType" name="resourceType" >
                    <option value="1">菜单</option>
                    <option value="2">功能</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">链接：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="resourceUrl" name="resourceUrl">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="resourceOrderBy" name="resourceOrderBy">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">样式：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="resourceStyle" name="userNresourceStyleame">
            </div>
        </div>

        <button id="submit" type="submit" class="btn btn-success btn-submit">提交</button>

    </div>
</form>
<script type="text/javascript">
    jQuery(function ($) {
        var $form = $("#form");
        var $submit = $("#submit");

        $form.validate({
            rules: {
                parentId: "required",
                resourceName: "required",
                resourceType: "required",
                resourceOrderBy: {
                    required: true,
                    digits:true
                }
            },
            messages: {
                parentId: "请选择父级菜单",
                resourceName: "菜单名称不能为空",
                resourceType: "菜单类型不能为空",
                resourceOrderBy: {
                    required: "排序不能为空",
                    digits: "排序只能为数字"
                }
            },
            submitHandler: function(form) {
                $.ajax({
                    url:$form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function() {
                        $submit.prop("disabled", true);
                    },
                    success: function(data) {
                        if(data.status == '0'){
                            $submit.prop("disabled", false);
                            layer.confirm('菜单添加成功！是否关闭窗口？',{icon:1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageDialog);
                                parent.refreshCurNode();
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data.message, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function(xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });

    });
</script>
</body>
</html>
